<?php
namespace app\admin\controller;

use app\admin\service\ChargingService;
use think\App;
use think\Controller;

class Charging extends Controller
{
    private $chargingService;

    public function __construct(ChargingService $chargingService)
    {
        $this->chargingService = $chargingService;
        parent::__construct();
    }

    /**
     * 查看充电桩列表
     * User: zhouyao
     * Date: 2018/9/8
     * Time: 下午2:13
     * @return \think\response\Json
     * @throws \app\common\exception\AppException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function postIndex()
    {
        $input = $this->request->input;

        $result = $this->chargingService->index($input);
        return app_response(200, $result);
    }

    /**
     * 添加充电桩信息
     * User: zhouyao
     * Date: 2018/9/8
     * Time: 下午2:11
     * @return \think\response\Json
     * @throws \app\common\exception\AppException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function postStore()
    {
        $input = $this->request->input;
        $result = $this->chargingService->store($input);
        $code = 200;
        if ($result === false) {
            $code = 9996;
        }

        return app_response($code, $result);
    }

    /**
     * 查询指定充电桩数据
     * User: zhouyao
     * Date: 2018/9/8
     * Time: 下午1:55
     * @return \think\response\Json
     * @throws \app\common\exception\AppException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function postEdit()
    {
        $input = $this->request->input;
        $result = $this->chargingService->edit($input);
        $code = 200;
        if ($result === false) {
            $code = 9998;
        }

        return app_response($code, $result);
    }

    /**
     * 修改充电桩类型信息
     * User: zhouyao
     * Date: 2018/9/8
     * Time: 下午2:11
     * @return \think\response\Json
     * @throws \app\common\exception\AppException
     */
    public function postUpdate()
    {

        $input = $this->request->input;
        $result = $this->chargingService->update($input);
        $code = 200;
        if ($result === false) {
            $code = 9998;
        }

        return app_response($code, '编辑成功');
    }
}